package com.boot.dog.rest.core;

import com.boot.dog.common.annotation.SysLog;
import com.boot.dog.common.util.ApiResult;
import com.boot.dog.entities.pojo.Organization;
import com.boot.dog.service.AreaService;
import com.boot.dog.service.OrganizationService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: MaxLv
 * @Date: 2020/1/16
 */
@RestController
@RequestMapping("/core/org")
@AllArgsConstructor
public class OrganizationRest {

    private final OrganizationService organizationService;

    private final AreaService areaService;

    @GetMapping("/getOrgByParentId")
    @ApiOperation(value = "获取下级机构")
    public ApiResult<List<Organization>> getOrgByParentId(@RequestParam Integer parentId, @RequestParam Integer level) {
        Map<Integer, List<Integer>> map = areaService.currUserArea();
        return organizationService.getOrgByParentId(parentId, level, map);
    }

    @PostMapping("/saveOrg")
    @SysLog(desc = "添加机构")
    @ApiOperation(value = "添加机构")
    public ApiResult<Void> saveOrg(@RequestBody Organization org) {
        return organizationService.saveOrg(org);
    }

    @PostMapping("/editOrg")
    @SysLog(desc = "编辑机构")
    @ApiOperation(value = "编辑机构")
    public ApiResult<Void> editOrg(@RequestBody Organization org) {
        return organizationService.editOrg(org);
    }

    @DeleteMapping("/delById/{id}")
    @SysLog(desc = "删除机构")
    @ApiOperation(value = "删除机构")
    public ApiResult<Void> delById(@PathVariable Integer id) {
        return organizationService.delById(id);
    }

    @GetMapping("/searchOrg")
    @ApiOperation(value = "检索机构")
    public ApiResult<List<Organization>> searchOrg(@RequestParam String title) {
        Map<Integer, List<Integer>> map = areaService.currUserArea();
        return organizationService.searchOrg(title, map);
    }

/*    @GetMapping("/getAllOrg")
    @ApiOperation(value = "机构树")
    public ApiResult<List<Organization>> getAllOrg() {
        Map<Integer, List<Integer>> map = areaService.currUserArea();
        return organizationService.getAllOrg(map);
    }*/
}
